<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php
	include_once("include/config.php");
	include_once("include/auth.lib.php");
	include_once("include/functions.php");

	setcookie ("uid", "", time() - 3600);
?>
<html>
	<head>
		<title><?php echo TITLE ?></title>
		<link href="lib/jqueryui/development-bundle/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css"/>
		<link href="judoinvorio.css" rel="stylesheet" type="text/css"/>
		
		<script src="lib/jquery.js"></script>
		<script src="lib/jquery-ui.min.js"></script>
		
		<script>
			$(document).ready(function() {
				$("input:button, input:reset, input:submit").button();
			});
			
			function show(value) {
				if (value == 'registrazione') {
					$('#login').hide('slow');
					$('#reg-form').show('slow');
					$('#recupero-form').hide('slow');
				} else if (value == 'login') {
					$('#login').show('slow');
					$('#reg-form').hide('slow');
					$('#recupero-form').hide('slow');
				} else if (value == 'recupero') {
					$('#login').hide('slow');
					$('#reg-form').hide('slow');
					$('#recupero-form').show('slow');
				}				
			}
			
			function doSubmit() {
				if ($('#username').val() == '' || $('#password').val() == '') {
					$( "#dialog-validation" ).dialog({
						resizable: false,
						modal: true,
						buttons: {
							"Ok": function() {
								$(this).dialog( "close" );
							}
						}
					});
					return false;
				} else {
					$('#login-form').submit();
				}
			}

			function doRegistration() {
				if ($('#username-reg').val() == '' || $('#nome').val() == '' || $('#codice-federale').val() == '' ||
					$('#email').val() == '' || $('#password-reg').val() == '' ||				
				    $('#rippassword').val() == '') {
					$( "#registration-validation" ).dialog({
						resizable: false,
						modal: true,
						buttons: {
							"Ok": function() {
								$(this).dialog( "close" );
							}
						}
					});
					return false;
				} else {
					$('#reg-form').submit();
				}
			}			
		</script>
		
	</head>
<body>

	<div id="dialog-validation" title="Errore" style="display:none;color:red">
		<p><span style="float:left; margin:0 7px 20px 0;"></span>Username e Password sono obbligatori</p>
	</div>
	
	<div id="registration-validation" title="Errore" style="display:none;color:red">
		<p><span style="float:left; margin:0 7px 20px 0;"></span>
		I seguenti campi sono obbligatori:
		<ul>
			<li>Username</li>
			<li>Nome palestra</li>
			<li>Codice federale</li>
			<li>Email</li>
			<li>Password</li>
			<li>Ripeti password</li>
		</p>
	</div>
	
	<table id="title">
		<tr><td>Iscrizione Trofeo Judo Invorio 2011</td></tr>
		<tr><td>Posti disponibili: <?php echo MAX_ISCRIZIONI - countRec('*', 'atleti'); ?></td></tr>
		<!--<tr><td><img src="images/logo.gif"></td></tr>-->
	</table>
	
	<form action="login.php" method="POST" id="login-form">
		
		<input id="backUrl" name="backUrl" type="hidden">
		<table id="login" width="400">
			<tr><td align="center" colspan=2></td></tr>
			<tr><td align="right"><b>Username:</b></td><td align="right"><input name="username" id="username" type="text" value=""></td></tr>
			<tr><td align="right"><b>Password:</b></td><td align="right"><input name="password" id="password" type="password" value=""></td></tr>
			<tr><td align="right" colspan=2><input type="button" value="Entra" onclick="doSubmit()"></td></tr>
			<tr><td align="left"><a href="javascript:show('registrazione')">Registrazione</a></td><td align="right"><a href="javascript:show('recupero')">Password dimenticata</a></td></tr>
		</table>
	</form>	

	<form id="reg-form" action="salva.php" method="POST" style="display:none">
		<table id="reg-table" width="500">
			<tr>
				<td><b>Username</b></td><td colspan=2><input type="text" name="USERNAME" id="username-reg"></td><td></td>
			</tr><tr>
				<td><b>Nome palestra</b></td><td colspan=2><input type="text" name="NOME" id="nome"></td><td></td>
			</tr><tr>
				<td><b>Codice federale</b></td><td colspan=2><input type="text" name="CODICE_FEDERALE" id="codice-federale"></td><td></td>
			</tr><tr>
				<td>Istruttore</td><td colspan=2><input type="text" name="ISTRUTTORE"></td><td></td>
			</tr><tr>
				<td><b>Email</b></td><td colspan=2><input type="text" name="EMAIL" id="email"></td><td></td>
			</tr><tr>
				<td>Sito</td><td colspan=2><input type="text" name="SITO"></td><td></td>
			</tr><tr>
				<td><b>Password</b></td><td colspan=2><input type="password" name="PASSWORD" id="password-reg"></td><td></td>
			</tr><tr>
				<td><b>Ripeti password</b></td><td colspan=2><input type="password" name="NPSWD" id="rip-password"></td><td></td>
			</tr><tr>
				<td colspan=3>&nbsp;</td>
			</tr><tr>
				<td><input align="center" type="button" value="Invio" onclick="doRegistration()"></td><td><input align="center" type="reset" value="Cancella"></td><td><input  align="center"type="button" value="Indietro" onclick="show('login')"></td>
			</tr>
		</table>
	</form>
	
	<form id="recupero-form" action="recupero.php" method="POST" style="display:none">
		<table id="recupero-table" width="500">
			<tr>
				<td><b>Email</b></td><td colspan=2><input type="text" name="RECUPERO-EMAIL" id="recupero-email"></td>
			</tr><tr>
				<td colspan=3>&nbsp;</td>
			</tr><tr>
				<td><input align="center" type="submit" value="Invio"></td><td><input  align="center"type="button" value="Indietro" onclick="show('login')"></td>
			</tr>
		</table>
	</form>	
</body>
</html>